using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class ProviderAuthCodeDB
    {
        public ProviderAuthCodeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ProviderAuthCode providerauthcode)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderAuthCodeInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderAuthCodeId", providerauthcode.ProviderAuthCodeId);
            _sPara.Add("@ProviderCompanyId", providerauthcode.ProviderCompanyId);
            _sPara.Add("@AuthCodeType", providerauthcode.AuthCodeType);
            _sPara.Add("@AuthCode", providerauthcode.AuthCode);
            _sPara.Add("@RefCEUserID", providerauthcode.RefCEUserID);
            _sPara.Add("@Status", providerauthcode.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ProviderAuthCodeList GetProviderAuthCodeList(Int64 ProviderCompanyId)
        {
            ProviderAuthCodeList _providerauthcodelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderAuthCodeSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _providerauthcodelist = new ProviderAuthCodeList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        ProviderAuthCode _authcode = new ProviderAuthCode();
                        _authcode = FillDataRecord(_dt, i);
                        _providerauthcodelist.Add(_authcode);
                    }
                }
            }
            return _providerauthcodelist;
        }

        public ProviderAuthCode GetProviderAuthCode(Int64 ProviderAuthCodeId)
        {
            ProviderAuthCode _authcode = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderAuthCodeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderAuthCodeId", ProviderAuthCodeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _authcode = new ProviderAuthCode();
                    _authcode = FillDataRecord(_dt, 0);
                }
            }
            return _authcode;
        }

        public ProviderAuthCode GetProviderAuthCode(Int64 ProviderCompanyId, Int32 AuthCodeType, string AuthCode)
        {
            ProviderAuthCode _authcode = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderAuthCodeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@AuthCodeType", AuthCodeType);
            _spara.Add("@AuthCode", AuthCode);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _authcode = new ProviderAuthCode();
                    _authcode = FillDataRecord(_dt, 0);
                }
            }
            return _authcode;
        }

        private ProviderAuthCode FillDataRecord(DataTable myDataTable, int RowId)
        {
            ProviderAuthCode myAuthCode = new ProviderAuthCode();
            myAuthCode.ProviderAuthCodeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderAuthCodeId"].ToString());
            myAuthCode.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myAuthCode.AuthCodeType = Convert.ToInt32(myDataTable.Rows[RowId]["AuthCodeType"].ToString());
            myAuthCode.AuthCode = myDataTable.Rows[RowId]["AuthCode"].ToString();
            myAuthCode.RefCEUserID = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myAuthCode.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            return myAuthCode;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public bool Delete(Int64 ProviderAuthCodeId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderAuthCodeDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderAuthCodeId", ProviderAuthCodeId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

    }
}